package com.example.shoppings.activity;

import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.design.widget.FloatingActionButton;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.example.shoppings.R;
import com.example.shoppings.fragment.AddCartFragment;
import com.example.shoppings.sql.Products;
import com.example.shoppings.utils.GlideImageLoader;
import com.youth.banner.Banner;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * Created by hasee on 2017-05-10.
 */

public class ProductDetailActivity extends AppCompatActivity {

    @BindView(R.id.banner)
    Banner banner;
    @BindView(R.id.toolbar)
    Toolbar toolbar;
    @BindView(R.id.tv_msg)
    TextView tvMsg;
    @BindView(R.id.tv_price)
    TextView tvPrice;
    @BindView(R.id.tv_content1)
    TextView tvContent1;
    @BindView(R.id.iv_detail)
    ImageView ivDetail;
    @BindView(R.id.tv_content2)
    TextView tvContent2;
    @BindView(R.id.main_content)
    LinearLayout mainContent;
    @BindView(R.id.float_actionBar)
    FloatingActionButton floatActionBar;

    private Products products;
    private String[] strDetail;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.fragment_productdetail);
        ButterKnife.bind(this);
        products= (Products) getIntent().getSerializableExtra("product");


        if(products!=null){
            setToolbar();//设置Toolbar
            setContentData();
        }
    }

    private void setToolbar(){

        toolbar.setTitle(products.getProName());
        toolbar.setSubtitle(products.getProName());
        toolbar.setNavigationIcon(R.mipmap.back);
        setSupportActionBar(toolbar);
        toolbar.setNavigationOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                onBackPressed();
            }
        });
    }

    private void setContentData(){
        if(products.getProName().equals("FLYTE")){
            tvContent1.setText(R.string.proDetail1);
            tvContent2.setText(R.string.proDetail1s);
        }else{
            tvContent1.setText(R.string.proDetail2);
            tvContent2.setText(R.string.proDetail2s);
        }
        tvMsg.setText(products.getProMsg());
        tvPrice.setText("￥："+products.getProPrice());
        ivDetail.setImageResource(products.getImgDetailPath().get(0));
        banner.setImages(products.getImgMainPath()).setImageLoader(new GlideImageLoader()).start();

    }

    @OnClick(R.id.float_actionBar)
    public void onClick() {
        Intent intent=new Intent(ProductDetailActivity.this, AddCartFragment.class);
        Bundle b=new Bundle();
        b.putSerializable("product",products);
        intent.putExtras(b);
        startActivity(intent);
    }
}
